<div class="da-list-wrap">
  <div class="da-content-banner">
    <d-breadcrumb>
      <d-breadcrumb-item><a routerLink="/">{{ 'basicdata.breadcrumb.home' | translate }}</a></d-breadcrumb-item>
      <d-breadcrumb-item><a routerLink="/pages/sales-master/sales-Invoice">销售发货单</a></d-breadcrumb-item>
      <d-breadcrumb-item>销售发货单—维护</d-breadcrumb-item>
    </d-breadcrumb>
  </div>
  <div class="da-content-wrapper">
    <div class="da-form-container ">
      <div class="card">
        <form dForm ngForm [layout]="layoutDirection" [labelSize]="'sm'" [labelAlign]="'end'"
          (dSubmit)="submit($event)">
          <div class="form-header">
            <p class="form-title">销售发货单—维护</p>
            <div class="form-head-btnGroup">
              <d-button class="me-3" (btnClick)="selectOrder()">选源单</d-button>
              <d-button class="me-3" bsStyle="primary" dFormSubmit>确定</d-button>
              <d-button class="me-3" bsStyle="primary" dFormSubmit (btnClick)="isStartApprovalChange()">确定并发起审核</d-button>
              <d-button bsStyle="common" (btnClick)="cancel()">取消</d-button>
            </div>
          </div>
          <div class="form-body">
            <div>
              <h4>基本信息</h4>
            </div>
            <div class="grid mt-3">
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>销售发货单号</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput type="text" name="销售订单号" [(ngModel)]="saleDeliver.saleDeliverNum">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>客户名称</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="客户名称" [(ngModel)]="saleDeliver.chineseName" readonly
                      (click)="selectCustomerBefore('warning')" [dValidateRules]="saleOrderRules.customerName">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>单据日期</span>
                  </d-form-label>
                  <d-form-control>
                    <d-datepicker-pro name="单据日期" [appendToBody]="false" [(ngModel)]="saleDeliver.orderDate"
                      [dValidateRules]="saleOrderRules.orderDate"></d-datepicker-pro>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label"><span class="Required">*</span>发货时间</span>
                  </d-form-label>
                  <d-form-control>
                    <d-datepicker-pro name="发货时间" [appendToBody]="false" [(ngModel)]="saleDeliver.scheduledDeliverTime"
                      [dValidateRules]="saleOrderRules.deliveryDate"></d-datepicker-pro>
                  </d-form-control>
                </d-form-item>
              </div>

              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">客户简称</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="客户简称" [(ngModel)]="saleDeliver.customerAbbreviation">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">客户联系人</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select name="客户联系人" [options]="customerLinkMan" [(ngModel)]="saleDeliver.customerContactName"
                      [filterKey]="'customerContactName'" (ngModelChange)="slectLinkMan($event)">
                    </d-select>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">联系方式</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="联系方式" [(ngModel)]="saleDeliver.customerContactPhone">
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">业务员</span>
                  </d-form-label>
                  <d-form-control>
                    <input type="text" dTextInput name="业务员" [(ngModel)]="saleDeliver.salesmanName" readonly
                      (click)="selectUser()"  [dValidateRules]="saleOrderRules.salesmanName">
                  </d-form-control>
                </d-form-item>
              </div>
              <!-- <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">结算币种</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select name="结算币种" [options]="currencyOptions" [(ngModel)]="saleDeliver.currencyName"
                      [filterKey]="'currencyName'" [disabled]="true" [valueKey]="'currencyName'">
                    </d-select>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">结算方式</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select name="结算方式" [options]="settlementMethodOptions"
                      [(ngModel)]="saleDeliver.settlementMethodName" [filterKey]="'settlementMethodName'"
                      [valueKey]="'settlementMethodName'" [disabled]="true" >
                    </d-select>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">收款账期</span>
                  </d-form-label>
                  <d-form-control>
                    <d-select name="收款账期" [options]="collectionPeriods" [(ngModel)]="saleDeliver.collectionPeriodName"
                      [valueKey]="'collectionPeriodName'" [filterKey]="'collectionPeriodName'" [disabled]="true" >
                    </d-select>
                  </d-form-control>
                </d-form-item>
              </div> -->
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">交货地址</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="交货地址" [(ngModel)]="saleDeliver.deliveryAddress" [disabled]="true" >
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1">
                <d-form-item>
                  <d-form-label>
                    <span class="label">备注</span>
                  </d-form-label>
                  <d-form-control class="textarea">
                    <textarea dTextarea name="备注" [(ngModel)]="saleDeliver.note"></textarea>
                  </d-form-control>
                </d-form-item>
              </div>
            </div>
            <div>
              <h4>物料信息</h4>
            </div>
            <div class="table">
              <d-data-table [lazy]="true" [scrollable]="true" [fixHeader]="true" [scrollable]="true" [resizeable]="true"
                [tableWidthConfig]="tableWidthConfig" [dataSource]="this.saleDeliver.saleDeliverParts">
                <thead dTableHead>
                  <tr dTableRow>
                    <th dHeadCell [fixedLeft]="'0px'">
                      <span>操作</span>
                    </th>
                    <th dHeadCell dTooltip [content]="colOption.header"
                      *ngFor="let colOption of dataTableOptions.columns">
                      {{colOption.header}}</th>
                  </tr>
                </thead>
                <tbody dTableBody>
                  <ng-template let-rowItem="rowItem" let-rowIndex="rowIndex">
                    <tr dTableRow>
                      <td dTableCell [fixedLeft]="'0px'">
                        <span (click)="addRow(rowIndex,rowItem)"><i class="icon-code-editor-add add"></i></span>
                        <span (click)="deleteRow(rowIndex)" class="ms-3"><i class="icon-code-editor-less minus" style="font-size: 16px;"></i></span>
                      </td>
                      <td dTableCell>
                        <input type="text" dTextInput [ngModelOptions]="{standalone: true}" [(ngModel)]="rowItem.partNum" readonly [dValidateRules]="saleOrderRules.partNum">
                      </td>
                      <td dTableCell>
                        <span>
                          <div dImagePreview>
                            <d-badge *ngIf="rowItem.image" [count]="getImagesArray(rowItem.image).length" status="success">
                              <ng-container *ngFor="let imageUrl of getImagesArray(rowItem.image); let i = index">
                                <img *ngIf="getImagesArray(rowItem.image).length > 0" [src]="imageUrl" alt="图片" width="30px" height="30px" [ngStyle]="{'display': i === 0 ? 'block' : 'none'}" />
                              </ng-container>
                            </d-badge>
                          </div>
                        </span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.partName">{{rowItem.partName}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.partType">{{rowItem.partType}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.description">{{rowItem.description}}</span>
                      </td>
                      <td dTableCell>
                        <d-datepicker-pro [appendToBody]="true" [ngModelOptions]="{standalone: true}" [(ngModel)]="rowItem.scheduledDeliverTime" [dValidateRules]="saleOrderRules.plannedShipmentDate"></d-datepicker-pro>
                      </td>
                      <td dTableCell>
                        <d-input-number [(ngModel)]="rowItem.scheduledDeliverAmount" class="input-number" [min]="0" (ngModelChange)="quantityChange(rowItem)" [ngModelOptions]="{standalone: true}" [dValidateRules]="saleOrderRules.quantity"></d-input-number>
                      </td>
                      <td dTableCell>
                        <input type="text" dTextInput name="仓库" readonly [(ngModel)]="rowItem.warehouseName" (click)="SelectStorehouse(rowItem)">
                      </td>
                      <td dTableCell>
                        <input type="text" dTextInput name="仓位" readonly [(ngModel)]="rowItem.positionName" (click)="SelectStorehouse(rowItem)">
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.realTimeInventory">{{rowItem.realTimeInventory}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.partUOM">{{rowItem.partUOM}}</span>
                      </td>
                      <td dTableCell>
                        <d-input-number [min]="0" [(ngModel)]="rowItem.priceWithTax" class="input-number" (ngModelChange)="priceWithTaxChange(rowItem)" [ngModelOptions]="{standalone: true}" [dValidateRules]="saleOrderRules.priceWithTax" [disabled]="true"></d-input-number>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.priceWithoutTax">{{rowItem.priceWithoutTax}}</span>
                      </td>
                      <td dTableCell>
                        <d-input-number [min]="0" [ngModel]="Math.floor(rowItem.taxRate * 100)" [disabled]="true" [ngModelOptions]="{standalone: true}" class="input-number" (afterValueChanged)="taxRateChange(rowItem, $event)"></d-input-number>
                      </td>
                      <td dTableCell>
                        <d-input-number [min]="0" [ngModel]="Math.floor(rowItem.discount * 100)" [ngModelOptions]="{standalone: true}" class="input-number" (afterValueChanged)="discountChange(rowItem, $event)" [disabled]="true"></d-input-number>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.discountPriceWithTax">{{rowItem.discountPriceWithTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.amountWithTax">{{rowItem.amountWithTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.amountWithoutTax">{{rowItem.amountWithoutTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.taxAmount">{{rowItem.taxAmount}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.discountAmountWithoutTax">{{rowItem.discountAmountWithoutTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.discountAmountWithTax">{{rowItem.discountAmountWithTax}}</span>
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.discountTaxAmount">{{rowItem.discountTaxAmount}}</span>
                      </td>
                      <td dTableCell>
                        <input type="text" dTextInput [ngModelOptions]="{standalone: true}" [(ngModel)]="rowItem.note">
                      </td>
                      <td dTableCell>
                        <span dTooltip [content]="rowItem.saleOrderNum">{{rowItem.saleOrderNum}}</span>
                      </td>
                    </tr>
                  </ng-template>
                </tbody>
              </d-data-table>
              <div class="table-btn">
                <d-button bsStyle="primary" class="ms-3" (btnClick)="setDeliveryDate()">批量设置发货日期</d-button>
              </div>
            </div>
            <div class="mt-5">
              <h4>费用及收款</h4>
            </div>
            <div class="grid mt-3">
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">数量合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="数量合计" [(ngModel)]="saleDeliver.amount" disabled>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">金额合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="金额合计（含税）" [(ngModel)]="saleDeliver.taxAmount" disabled>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">税额合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="税额合计" [(ngModel)]="saleDeliver.tax" disabled>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">折扣金额合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="折扣金额合计" [(ngModel)]="saleDeliver.taxDiscountAmount"
                      disabled>
                  </d-form-control>
                </d-form-item>
              </div>
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">折扣税额合计</span>
                  </d-form-label>
                  <d-form-control>
                    <input dTextInput class="form-input-box" name="折扣税额合计" [(ngModel)]="saleDeliver.taxDiscount"
                      disabled>
                  </d-form-control>
                </d-form-item>
              </div>
            </div>
            <div>
              <h4>其他</h4>
            </div>
            <div class="grid mt-3">
              <div class="u-1-3">
                <d-form-item>
                  <d-form-label>
                    <span class="label">附件</span>
                  </d-form-label>
                  <d-form-control>
                    <d-button bsStyle="common" class="ms-3"><i
                        class="icon icon-upload me-2"></i><span>附件</span></d-button>
                  </d-form-control>
                </d-form-item>
              </div>
            </div>
          </div>
          <d-form-operation class="form-footer">
            制单人：{{saleDeliver.createUser}}
          </d-form-operation>
        </form>
      </div>
    </div>
  </div>
</div>
<d-toast [value]="msgs" [life]="2000" [styleClass]="'custom-class'" [style]="{ left: '50%',top:'10px' }"></d-toast>
